Repository navigation
Conversation
computeUnrealizedPnLPercent 增加可选 quantity 参数,负数时取反,使百分比与 computeUnrealizedPnL 的金额同号;两参数旧调用、零值与非有限数保持原价格口径。 normalizeHolding 传入 quantity,并补空头正反两向与兼容性用例。 Closes helsome#397
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
改了什么
packages/longbridge-tools/src/normalizer.ts:computeUnrealizedPnLPercent增加可选的第三个参数quantity;传入负数时按空头方向取反,使百分比与computeUnrealizedPnL(cost, market, quantity)的金额同号。normalizeHolding调用处传入quantity。quantity(原有两参数调用)、quantity = 0或非有限数时,保持原纯价格口径。packages/longbridge-tools/src/normalizer.test.ts:新增两条用例,覆盖空头正反两向、金额与百分比同号断言,以及正数 / 零 / 非有限 / 缺失数量的兼容性。为什么要改
Issue #397 的复现:
quantity=-10, cost=100, market=120时金额为-$200,百分比却是+20%;market=80时金额+$200、百分比-20%。原因是百分比只看价格涨跌,不看数量方向,两个数字互相矛盾。金额、市值与权重语义不变,也没有反转 provider 已上报的 ratio。关联 Issue
Closes #397
测试报告
环境:Bun 1.4.4 / Windows 11 家庭版 10.0.26200 / AMD64;基线
f5822f0cb27b1f5843fe3ed5cc2f3f5baecc75de。关于 8 项 skip:均为既有跳过项(真实 CLI fixture 需要私有账户数据、phase-2 旧契约用例、Windows 符号链接需开发者模式),与本次改动无关,改动前后一致。
UI 截图
百分比数值会变(空头从
+20%变-20%),但这是数据正确性修复,不涉及组件结构、布局或样式;HoldingRow显示层未改动。Scope / 后续
只改百分比的符号口径。未改动金额、市值、权重,未引入 provider 已上报 ratio 的反转,未处理 #356–#360 的解析范围。